package com.itheima.tlias.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias.dao.LogDao;
import com.itheima.tlias.dto.PageDto;
import com.itheima.tlias.mapper.LogPageMapper;
import com.itheima.tlias.service.LogPageService;
import com.itheima.tlias.vo.LogVo;
import com.itheima.tlias.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LogPageServiceImpl implements LogPageService {
    @Autowired
    private LogDao logDao;
    @Autowired
    private LogPageMapper logMapper;

    public PageBean<LogVo> depts(PageDto dto)   {
        //读文件
     /*   List<String> logs = logDao.logs();
        List<Log> logList = logs.stream().map(line -> {
            String[] parts = line.split(",");
            Log log = new Log(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6]);
            return log;
        }).collect(Collectors.toList());*/
        //读数据库
        PageHelper.startPage(dto.getPage(),dto.getPageSize());
        Page<LogVo> logs = logMapper.logPage(dto);
        return new PageBean<>(logs.getTotal(),logs.getResult());
    }
}
